package io.renren.modules.project.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.project.entity.ProFuncTestEntity;
import io.renren.modules.project.entity.ProFuncTestEntity;
import io.renren.modules.project.service.ProFuncTestService;
import io.renren.modules.project.service.ProPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

import static io.renren.common.utils.ShiroUtils.getUserId;

@RestController
@RequestMapping(value = "/project/func-test")
public class ProFuncController {

    @Autowired
    private ProFuncTestService funcTestService;



    @GetMapping("/info/{funcId}")
    public R info(@PathVariable("funcId") Long funcId) {
        ProFuncTestEntity proPlan = funcTestService.getById(funcId);
        return R.ok().put("funcTest", proPlan);
    }

    @GetMapping(value = "list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = funcTestService.queryPage(params);

        return R.ok().put("page", page);
    }

    @PostMapping(value= "save")
    public R save(@RequestBody ProFuncTestEntity funcTest) {
        ValidatorUtils.validateEntity(funcTest);

        funcTest.setCreateTime(new Date());
        funcTest.setUpdateTime(null);
        funcTest.setCreateUserId(getUserId()); // 获取当前登录人
        funcTestService.save(funcTest);

        return R.ok();
    }

    @PostMapping(value= "update")
    public R update(@RequestBody ProFuncTestEntity proPlan) {
        ValidatorUtils.validateEntity(proPlan);

        proPlan.setUpdateTime(new Date());
        proPlan.setUpdateUserId(getUserId()); // 获取当前登录人

        funcTestService.saveOrUpdate(proPlan);

        return R.ok();
    }

    @PostMapping(value = "delete")
    public R delete(@RequestBody int[] planIds) {
        // funcTestService.deleteBatch(planIds);

        return R.ok();
    }
}
